Josh Dillon, Last Revised January 2022
This notebook examines an individual antenna's performance over a whole season. This notebook parses information from each nightly rtp_summarynotebook (as saved to .csvs) and builds a table describing antenna performance. It also reproduces per-antenna plots from each auto_metrics notebook pertinent to the specific antenna.
import os
from IPython.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
# If you want to run this notebook locally, copy the output of the next cell into the next line of this cell.
# antenna = "004"
# csv_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/_rtp_summary_'
# auto_metrics_folder = '/lustre/aoc/projects/hera/H5C/H5C_Notebooks/auto_metrics_inspect'
# os.environ["ANTENNA"] = antenna
# os.environ["CSV_FOLDER"] = csv_folder
# os.environ["AUTO_METRICS_FOLDER"] = auto_metrics_folder
# Use environment variables to figure out path to the csvs and auto_metrics
antenna = str(int(os.environ["ANTENNA"]))
csv_folder = os.environ["CSV_FOLDER"]
auto_metrics_folder = os.environ["AUTO_METRICS_FOLDER"]
print(f'antenna = "{antenna}"')
print(f'csv_folder = "{csv_folder}"')
print(f'auto_metrics_folder = "{auto_metrics_folder}"')
antenna = "185" csv_folder = "/home/obs/src/H6C_Notebooks/_rtp_summary_" auto_metrics_folder = "/home/obs/src/H6C_Notebooks/auto_metrics_inspect"
display(HTML(f'<h1 style=font-size:50px><u>Antenna {antenna} Report</u><p></p></h1>'))
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', 1000)
import glob
import re
from hera_notebook_templates.utils import status_colors, Antenna
# load csvs and auto_metrics htmls in reverse chronological order
csvs = sorted(glob.glob(os.path.join(csv_folder, 'rtp_summary_table*.csv')))[::-1]
print(f'Found {len(csvs)} csvs in {csv_folder}')
auto_metric_htmls = sorted(glob.glob(auto_metrics_folder + '/auto_metrics_inspect_*.html'))[::-1]
print(f'Found {len(auto_metric_htmls)} auto_metrics notebooks in {auto_metrics_folder}')
Found 13 csvs in /home/obs/src/H6C_Notebooks/_rtp_summary_ Found 12 auto_metrics notebooks in /home/obs/src/H6C_Notebooks/auto_metrics_inspect
# Per-season options
mean_round_modz_cut = 4
dead_cut = 0.4
crossed_cut = 0.0
def jd_to_summary_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/_rtp_summary_/rtp_summary_{jd}.html'
def jd_to_auto_metrics_url(jd):
return f'https://htmlpreview.github.io/?https://github.com/HERA-Team/H6C_Notebooks/blob/main/auto_metrics_inspect/auto_metrics_inspect_{jd}.html'
this_antenna = None
jds = []
# parse information about antennas and nodes
for csv in csvs:
df = pd.read_csv(csv)
for n in range(len(df)):
# Add this day to the antenna
row = df.loc[n]
if isinstance(row['Ant'], str) and '<a href' in row['Ant']:
antnum = int(row['Ant'].split('</a>')[0].split('>')[-1]) # it's a link, extract antnum
else:
antnum = int(row['Ant'])
if antnum != int(antenna):
continue
if np.issubdtype(type(row['Node']), np.integer):
row['Node'] = str(row['Node'])
if type(row['Node']) == str and row['Node'].isnumeric():
row['Node'] = 'N' + ('0' if len(row['Node']) == 1 else '') + row['Node']
if this_antenna is None:
this_antenna = Antenna(row['Ant'], row['Node'])
jd = [int(s) for s in re.split('_|\.', csv) if s.isdigit()][-1]
jds.append(jd)
this_antenna.add_day(jd, row)
break
# build dataframe
to_show = {'JDs': [f'<a href="{jd_to_summary_url(jd)}" target="_blank">{jd}</a>' for jd in jds]}
to_show['A Priori Status'] = [this_antenna.statuses[jd] for jd in jds]
df = pd.DataFrame(to_show)
# create bar chart columns for flagging percentages:
bar_cols = {}
bar_cols['Auto Metrics Flags'] = [this_antenna.auto_flags[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jee)'] = [this_antenna.dead_flags_Jee[jd] for jd in jds]
bar_cols[f'Dead Fraction in Ant Metrics (Jnn)'] = [this_antenna.dead_flags_Jnn[jd] for jd in jds]
bar_cols['Crossed Fraction in Ant Metrics'] = [this_antenna.crossed_flags[jd] for jd in jds]
bar_cols['Flag Fraction Before Redcal'] = [this_antenna.flags_before_redcal[jd] for jd in jds]
bar_cols['Flagged By Redcal chi^2 Fraction'] = [this_antenna.redcal_flags[jd] for jd in jds]
for col in bar_cols:
df[col] = bar_cols[col]
z_score_cols = {}
z_score_cols['ee Shape Modified Z-Score'] = [this_antenna.ee_shape_zs[jd] for jd in jds]
z_score_cols['nn Shape Modified Z-Score'] = [this_antenna.nn_shape_zs[jd] for jd in jds]
z_score_cols['ee Power Modified Z-Score'] = [this_antenna.ee_power_zs[jd] for jd in jds]
z_score_cols['nn Power Modified Z-Score'] = [this_antenna.nn_power_zs[jd] for jd in jds]
z_score_cols['ee Temporal Variability Modified Z-Score'] = [this_antenna.ee_temp_var_zs[jd] for jd in jds]
z_score_cols['nn Temporal Variability Modified Z-Score'] = [this_antenna.nn_temp_var_zs[jd] for jd in jds]
z_score_cols['ee Temporal Discontinuties Modified Z-Score'] = [this_antenna.ee_temp_discon_zs[jd] for jd in jds]
z_score_cols['nn Temporal Discontinuties Modified Z-Score'] = [this_antenna.nn_temp_discon_zs[jd] for jd in jds]
for col in z_score_cols:
df[col] = z_score_cols[col]
ant_metrics_cols = {}
ant_metrics_cols['Average Dead Ant Metric (Jee)'] = [this_antenna.Jee_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Dead Ant Metric (Jnn)'] = [this_antenna.Jnn_dead_metrics[jd] for jd in jds]
ant_metrics_cols['Average Crossed Ant Metric'] = [this_antenna.crossed_metrics[jd] for jd in jds]
for col in ant_metrics_cols:
df[col] = ant_metrics_cols[col]
redcal_cols = {}
redcal_cols['Median chi^2 Per Antenna (Jee)'] = [this_antenna.Jee_chisqs[jd] for jd in jds]
redcal_cols['Median chi^2 Per Antenna (Jnn)'] = [this_antenna.Jnn_chisqs[jd] for jd in jds]
for col in redcal_cols:
df[col] = redcal_cols[col]
# style dataframe
table = df.style.hide_index()\
.applymap(lambda val: f'background-color: {status_colors[val]}' if val in status_colors else '', subset=['A Priori Status']) \
.background_gradient(cmap='viridis', vmax=mean_round_modz_cut * 3, vmin=0, axis=None, subset=list(z_score_cols.keys())) \
.background_gradient(cmap='bwr_r', vmin=dead_cut-.25, vmax=dead_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.background_gradient(cmap='bwr_r', vmin=crossed_cut-.25, vmax=crossed_cut+.25, axis=0, subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.background_gradient(cmap='plasma', vmax=4, vmin=1, axis=None, subset=list(redcal_cols.keys())) \
.applymap(lambda val: 'font-weight: bold' if val < dead_cut else '', subset=list([col for col in ant_metrics_cols if 'dead' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val < crossed_cut else '', subset=list([col for col in ant_metrics_cols if 'crossed' in col.lower()])) \
.applymap(lambda val: 'font-weight: bold' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.applymap(lambda val: 'color: red' if val > mean_round_modz_cut else '', subset=list(z_score_cols.keys())) \
.bar(subset=list(bar_cols.keys()), vmin=0, vmax=1) \
.format({col: '{:,.4f}'.format for col in z_score_cols}) \
.format({col: '{:,.4f}'.format for col in ant_metrics_cols}) \
.format('{:,.2%}', na_rep='-', subset=list(bar_cols.keys())) \
.set_table_styles([dict(selector="th",props=[('max-width', f'70pt')])])
This table reproduces each night's row for this antenna from the RTP Summary notebooks. For more info on the columns, see those notebooks, linked in the JD column.
display(HTML(f'<h2>Antenna {antenna}, Node {this_antenna.node}:</h2>'))
HTML(table.render(render_links=True, escape=False))
| JDs | A Priori Status | Auto Metrics Flags | Dead Fraction in Ant Metrics (Jee) | Dead Fraction in Ant Metrics (Jnn) | Crossed Fraction in Ant Metrics | Flag Fraction Before Redcal | Flagged By Redcal chi^2 Fraction | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | Average Dead Ant Metric (Jee) | Average Dead Ant Metric (Jnn) | Average Crossed Ant Metric | Median chi^2 Per Antenna (Jee) | Median chi^2 Per Antenna (Jnn) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2459826 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 0.416993 | 0.246281 | 1.412345 | 0.855555 | -0.094568 | -0.333808 | 40.395364 | -0.701874 | 0.8064 | 0.5940 | 0.5108 | 0.000000 | 0.000000 |
| 2459825 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | -0.087182 | 0.174708 | 6.976654 | 1.078551 | 3.851301 | 3.446951 | 9.080563 | 2.026399 | 0.7990 | 0.6044 | 0.5074 | 5.309364 | 5.709149 |
| 2459824 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | -0.152675 | -0.383861 | 5.389198 | 0.969771 | 18.705926 | 0.496632 | 13.189062 | 2.264257 | 0.7302 | 0.7459 | 0.3585 | 3.540722 | 4.254506 |
| 2459823 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.287174 | 0.169959 | 1.046617 | 0.880321 | -0.461142 | 1.249323 | 1.170286 | -0.308928 | 0.7627 | 0.6965 | 0.4107 | 2.656774 | 2.766368 |
| 2459822 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 0.893616 | 0.253119 | 1.192622 | 1.193590 | -0.559096 | -0.262099 | 1.295101 | 4.339682 | 0.8124 | 0.6293 | 0.5022 | 4.313038 | 3.920356 |
| 2459821 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 0.726201 | 0.005011 | 2.400320 | 1.060728 | 0.885007 | 0.708647 | -0.149530 | 4.884297 | 0.7980 | 0.6266 | 0.5097 | 3.937090 | 4.205261 |
| 2459820 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 1.094351 | 0.190205 | 2.449308 | 1.164057 | -0.408823 | -0.211886 | 0.353883 | -1.224053 | 0.7888 | 0.6907 | 0.4180 | 2.016108 | 1.784415 |
| 2459817 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.958231 | 0.076846 | 0.329357 | 0.996510 | 3.019987 | 1.192519 | 0.920917 | 0.676354 | 0.8034 | 0.6556 | 0.5091 | 1.958369 | 1.742989 |
| 2459816 | digital_ok | 100.00% | 0.00% | 0.00% | 0.00% | 100.00% | 0.00% | 1.598812 | 0.412561 | 1.032743 | 1.383686 | -0.373131 | 0.917810 | 5.083744 | -0.677993 | 0.8458 | 0.6051 | 0.5809 | 4.444794 | 4.172289 |
| 2459815 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.746553 | 0.491522 | 0.980881 | 0.996544 | -0.079801 | 0.646272 | 2.917438 | -0.529572 | 0.7936 | 0.6622 | 0.5164 | 2.146286 | 1.839843 |
| 2459814 | digital_ok | 0.00% | - | - | - | - | - | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan | nan |
| 2459813 | digital_ok | 0.00% | 0.00% | 0.00% | 0.00% | 0.53% | 0.00% | 2.139036 | 0.390880 | 1.164625 | 0.485230 | -0.517206 | -0.031750 | 1.552447 | -0.991701 | 0.7945 | 0.6923 | 0.4193 | 3.342429 | 2.415054 |
auto_metrics notebooks.¶htmls_to_display = []
for am_html in auto_metric_htmls:
html_to_display = ''
# read html into a list of lines
with open(am_html) as f:
lines = f.readlines()
# find section with this antenna's metric plots and add to html_to_display
jd = [int(s) for s in re.split('_|\.', am_html) if s.isdigit()][-1]
try:
section_start_line = lines.index(f'<h2>Antenna {antenna}: {jd}</h2>\n')
except ValueError:
continue
html_to_display += lines[section_start_line].replace(str(jd), f'<a href="{jd_to_auto_metrics_url(jd)}" target="_blank">{jd}</a>')
for line in lines[section_start_line + 1:]:
html_to_display += line
if '<hr' in line:
htmls_to_display.append(html_to_display)
break
These figures are reproduced from auto_metrics notebooks. For more info on the specific plots and metrics, see those notebooks (linked at the JD). The most recent 100 days (at most) are shown.
for i, html_to_display in enumerate(htmls_to_display):
if i == 100:
break
display(HTML(html_to_display))
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Temporal Discontinuties | 40.395364 | 0.246281 | 0.416993 | 0.855555 | 1.412345 | -0.333808 | -0.094568 | -0.701874 | 40.395364 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Temporal Discontinuties | 9.080563 | 0.174708 | -0.087182 | 1.078551 | 6.976654 | 3.446951 | 3.851301 | 2.026399 | 9.080563 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Temporal Variability | 18.705926 | -0.152675 | -0.383861 | 5.389198 | 0.969771 | 18.705926 | 0.496632 | 13.189062 | 2.264257 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | nn Temporal Variability | 1.249323 | 0.169959 | 0.287174 | 0.880321 | 1.046617 | 1.249323 | -0.461142 | -0.308928 | 1.170286 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | nn Temporal Discontinuties | 4.339682 | 0.893616 | 0.253119 | 1.192622 | 1.193590 | -0.559096 | -0.262099 | 1.295101 | 4.339682 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | nn Temporal Discontinuties | 4.884297 | 0.005011 | 0.726201 | 1.060728 | 2.400320 | 0.708647 | 0.885007 | 4.884297 | -0.149530 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Power | 2.449308 | 1.094351 | 0.190205 | 2.449308 | 1.164057 | -0.408823 | -0.211886 | 0.353883 | -1.224053 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | ee Shape Modified Z-Score | nn Shape Modified Z-Score | ee Power Modified Z-Score | nn Power Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Discontinuties Modified Z-Score | nn Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Temporal Variability | 3.019987 | 0.958231 | 0.076846 | 0.329357 | 0.996510 | 3.019987 | 1.192519 | 0.920917 | 0.676354 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Temporal Discontinuties | 5.083744 | 0.412561 | 1.598812 | 1.383686 | 1.032743 | 0.917810 | -0.373131 | -0.677993 | 5.083744 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Temporal Discontinuties | 2.917438 | 0.491522 | 0.746553 | 0.996544 | 0.980881 | 0.646272 | -0.079801 | -0.529572 | 2.917438 |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | nn Shape | nan | nan | nan | nan | nan | nan | nan | nan | nan |
| Ant | Node | A Priori Status | Worst Metric | Worst Modified Z-Score | nn Shape Modified Z-Score | ee Shape Modified Z-Score | nn Power Modified Z-Score | ee Power Modified Z-Score | nn Temporal Variability Modified Z-Score | ee Temporal Variability Modified Z-Score | nn Temporal Discontinuties Modified Z-Score | ee Temporal Discontinuties Modified Z-Score |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185 | N14 | digital_ok | ee Shape | 2.139036 | 0.390880 | 2.139036 | 0.485230 | 1.164625 | -0.031750 | -0.517206 | -0.991701 | 1.552447 |